package com.blueocean_health.care.management.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.blueocean_health.care.management.common.base.string.StringUtils;
import com.blueocean_health.care.management.domain.base.OrderChargeInfo;
import com.blueocean_health.care.management.domain.base.OrderInfo;
import com.blueocean_health.care.management.domain.base.OrderPayAccount;
import com.blueocean_health.care.management.domain.base.OrderPayInfo;
import com.blueocean_health.care.management.domain.base.OrderServiceInfo;
import com.blueocean_health.care.management.domain.base.OrderServiceNurseInfo;
import com.blueocean_health.care.management.domain.base.UserAccount;
import com.blueocean_health.care.management.domain.base.UserPatient;
import com.blueocean_health.care.management.domain.dto.AppSelectOrderInfoDto;
import com.blueocean_health.care.management.domain.dto.AppointmentOrderSelectInfoEntity;
import com.blueocean_health.care.management.domain.dto.ChargeInfoDto;
import com.blueocean_health.care.management.domain.dto.OrderDetailDto;
import com.blueocean_health.care.management.domain.dto.OrderInfoDto;
import com.blueocean_health.care.management.domain.dto.OrderSelectInfoEntity;
import com.blueocean_health.care.management.domain.dto.OrderSelectInfoReceivableEntity;
import com.blueocean_health.care.management.domain.dto.OrderSelectInfoToChargeEntity;
import com.blueocean_health.care.management.domain.dto.RelationListDto;
import com.blueocean_health.care.management.domain.dto.SOrderInfoEntity;
import com.blueocean_health.care.management.domain.dto.SOrderServiceInfoEntity;
import com.blueocean_health.care.management.domain.dto.SOrderServiceNurseInfoEntity;
import com.blueocean_health.care.management.domain.dto.SettlementDto;
import com.blueocean_health.care.management.domain.dto.SickRoomInfoDto;
import com.blueocean_health.care.management.domain.dto.WorkerDto;
import com.blueocean_health.care.management.domain.dto.WorkerInfoDto;
import com.blueocean_health.care.management.domain.ordervo.SelectOrderVo;
import com.blueocean_health.care.management.domain.ordervo.ToChargeVo;
import com.blueocean_health.care.management.em.AccountFlagEnum;
import com.blueocean_health.care.management.em.OrderStatusEnum;
import com.blueocean_health.care.management.em.OrderTypeEnum;
import com.blueocean_health.care.management.em.OrderUpdateFlagEnum;
import com.blueocean_health.care.management.em.PayStatusEnum;
import com.blueocean_health.care.management.mapper.OrderChargeInfoMapper;
import com.blueocean_health.care.management.mapper.OrderInfoMapper;
import com.blueocean_health.care.management.mapper.OrderPayAccountMapper;
import com.blueocean_health.care.management.mapper.OrderPayInfoMapper;
import com.blueocean_health.care.management.mapper.OrderSelectInfoEntityMapper;
import com.blueocean_health.care.management.mapper.OrderServiceInfoMapper;
import com.blueocean_health.care.management.mapper.OrderServiceNurseInfoMapper;
import com.blueocean_health.care.management.mapper.SOrderInfoEntityMapper;
import com.blueocean_health.care.management.mapper.UserAccountMapper;
import com.blueocean_health.care.management.service.IChareOrderService;
import com.blueocean_health.care.management.service.IOrderSelectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class OrderSelectServiceImpl implements IOrderSelectService {
	@Resource
	private OrderSelectInfoEntityMapper orderSelectInfoEntityMapper;
	@Resource
	private OrderChargeInfoMapper orderChargeInfoMapper;
	@Resource
	private SOrderInfoEntityMapper sOrderInfoEntityMapper;
	@Resource
	private OrderInfoMapper orderInfoMapper;
	@Resource
	private IChareOrderService iChareOrderService;
	@Resource
	private UserAccountMapper userAccountMapper;
	@Resource
	private OrderServiceInfoMapper orderServiceInfoMapper;
	@Resource
	private OrderPayInfoMapper orderPayInfoMapper;
	@Resource
	private OrderPayAccountMapper orderPayAccountMapper;
	@Resource
	private OrderServiceNurseInfoMapper orderServiceNurseInfoMapper;
	@Override
	// 查询订单列表
	public Map<String, Object> selectOrderList(SelectOrderVo order) {
		String sort = order.getSort() == null ? "" : order.getSort();
		if (sort.contains("remainingTime")) {
			sort = sort.replaceAll("remainingTime", "diff_date");
		}
		if (sort.contains("createTime")) {
			sort = sort.replaceAll("createTime", "create_time");
		} else {
			sort = "create_time  desc";
		}
		order.setSort(sort);
		if (!StringUtils.isEmpty(order.getStatus())) {
			String[] split = order.getStatus().split("\\.");
			order.setOrderStatus(split[0]);
			if (split.length > 1) {
				order.setPayStatus(split[1]);
			}
		}
		if (!StringUtils.isEmpty(order.getBeginTime())) {
			order.setBeginTime(order.getBeginTime() + " 00:00:00");
		}
		if (!StringUtils.isEmpty(order.getEndTime())) {
			order.setEndTime(order.getEndTime() + " 23:59:59");
		}
		if (!StringUtils.isEmpty(order.getStartBillingTime())) {
			order.setStartBillingTime(order.getStartBillingTime() + " 00:00:00");
		}
		if (!StringUtils.isEmpty(order.getEndBillingTime())) {
			order.setEndBillingTime(order.getEndBillingTime() + " 23:59:59");
		}
		order.setIspage(false);
		// 手动分页
		if (StringUtils.isEmpty(order.getUserId()) && StringUtils.isEmpty(order.getMaxReceiptNumber())
				&& StringUtils.isEmpty(order.getWorkerNames()) && StringUtils.isEmpty(order.getMinReceiptNumber())
				&& StringUtils.isEmpty(order.getTimeType()) && StringUtils.isEmpty(order.getStartBillingTime())
				&& StringUtils.isEmpty(order.getEndBillingTime())) {
			order.setIspage(true);
			int pagesizes = Integer.valueOf(StringUtils.isEmpty(order.getPageSize()) ? "65536" : order.getPageSize());
			int fromIndex = (Integer.valueOf(StringUtils.isEmpty(order.getPage()) ? "1" : order.getPage()) - 1)
					* Integer.valueOf(StringUtils.isEmpty(order.getPageSize()) ? "65536" : order.getPageSize());
			order.setFromIndex(fromIndex);
			order.setPageSizes(pagesizes);
		} else {
			PageHelper.startPage(Integer.valueOf(StringUtils.isEmpty(order.getPage()) ? "1" : order.getPage()),
					Integer.valueOf(StringUtils.isEmpty(order.getPageSize()) ? "65536" : order.getPageSize()), false);
		}
		List<OrderSelectInfoEntity> selectForList = orderSelectInfoEntityMapper.selectForList(order);
		for (OrderSelectInfoEntity orderSelectInfoEntity : selectForList) {
			String orderId = orderSelectInfoEntity.getOrderId();
//			String orderType = orderSelectInfoEntity.getOrderType();
//			if (orderType.equals(OrderTypeEnum._3.getKey()) || orderType == (OrderTypeEnum._3.getKey())) {
//				orderSelectInfoEntity.setPayStatus(PayStatusEnum._3.getKey());
//			}
			OrderInfo orderInfo = new OrderInfo();
			orderInfo.setDeflag("0");
			orderInfo.setRefundOrderId(orderId);
			double totalAmount = orderSelectInfoEntity.getTotalAmount() == null ? 0
					: orderSelectInfoEntity.getTotalAmount();
			double totalPay = orderSelectInfoEntity.getTotalPay() == null ? 0 : orderSelectInfoEntity.getTotalPay();
			Double proportion = 0.0;
			if (totalAmount != 0 && totalPay != 0) {
				proportion = totalPay / totalAmount * 100;
				BigDecimal b = new BigDecimal(proportion);
				proportion = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
			}

			orderSelectInfoEntity.setPayProportion(proportion + "%");
			// int selectCount = orderInfoMapper.selectCount(orderInfo);
			getgroupName(orderSelectInfoEntity);
			// orderSelectInfoEntity.setRefundsFlag(selectCount>0);

		}
		// PageInfo<OrderSelectInfoEntity> pageInfo = new
		// PageInfo<OrderSelectInfoEntity>(selectForList);
		Map<String, Object> selectCountList = orderSelectInfoEntityMapper.selectCountAndAmountList(order);
		Map<String, Object> pageInfomap = new HashMap<>();
		pageInfomap.put("total", (Long) selectCountList.get("count"));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pageInfo", pageInfomap);
		map.put("list", selectForList);
		map.put("allTotalAmount", selectCountList.get("all_total_amount"));
		return map;
	}

	// 查询是否有退款单
	@Override
	public Map<String, Boolean> checkHaveRefund(String orderId) {
		OrderInfo orderInfo = new OrderInfo();
		orderInfo.setDeflag("0");
		orderInfo.setRefundOrderId(orderId);
		int selectCount = orderInfoMapper.selectCount(orderInfo);
		Map<String, Boolean> map = new HashMap<String, Boolean>();
		map.put("isHaveRefund", selectCount > 0);
		return map;
	}

	// 查询预约单
	@Override
	public Map<String, Object> appointmentSelectOrderList(SelectOrderVo order) {
		String sort = order.getSort() == null ? "" : order.getSort();
		if (sort.contains("remainingTime")) {
			sort = sort.replaceAll("remainingTime", "diff_date");
		}
		if (sort.contains("createTime")) {
			sort = sort.replaceAll("createTime", "create_time");
		} else {
			sort = "create_time  desc";
		}
		order.setSort(sort);
		if (!StringUtils.isEmpty(order.getStatus())) {
			String[] split = order.getStatus().split("\\.");
			order.setOrderStatus(split[0]);
			if (split.length > 1) {
				order.setPayStatus(split[1]);
			}
		}
		if (!StringUtils.isEmpty(order.getBeginTime())) {
			order.setBeginTime(order.getBeginTime() + " 00:00:00");
		}
		if (!StringUtils.isEmpty(order.getEndTime())) {
			order.setEndTime(order.getEndTime() + " 23:59:59");
		}
		order.setIspage(false);
		if (StringUtils.isEmpty(order.getMaxReceiptNumber()) && StringUtils.isEmpty(order.getWorkerNames())
				&& StringUtils.isEmpty(order.getMinReceiptNumber())) {
			order.setIspage(true);
			int pagesizes = Integer.valueOf(StringUtils.isEmpty(order.getPageSize()) ? "65536" : order.getPageSize());
			int fromIndex = (Integer.valueOf(StringUtils.isEmpty(order.getPage()) ? "1" : order.getPage()) - 1)
					* Integer.valueOf(StringUtils.isEmpty(order.getPageSize()) ? "65536" : order.getPageSize());
			order.setFromIndex(fromIndex);
			order.setPageSizes(pagesizes);
		} else {
			PageHelper.startPage(Integer.valueOf(StringUtils.isEmpty(order.getPage()) ? "1" : order.getPage()),
					Integer.valueOf(StringUtils.isEmpty(order.getPageSize()) ? "65536" : order.getPageSize()));
		}
		List<OrderSelectInfoEntity> selectForList = orderSelectInfoEntityMapper.selectForList(order);
		List<AppointmentOrderSelectInfoEntity> appointmentSelectForList = new ArrayList<AppointmentOrderSelectInfoEntity>();
		for (OrderSelectInfoEntity orderSelectInfoEntity : selectForList) {
			String orderId = orderSelectInfoEntity.getOrderId();
			String orderType = orderSelectInfoEntity.getOrderType();
			if (orderType.equals(OrderTypeEnum._3.getKey()) || orderType == (OrderTypeEnum._3.getKey())) {
				orderSelectInfoEntity.setPayStatus(PayStatusEnum._3.getKey());
			}
			OrderInfo orderInfo = new OrderInfo();
			orderInfo.setDeflag("0");
			orderInfo.setRefundOrderId(orderId);
			// int selectCount = orderInfoMapper.selectCount(orderInfo);
			getgroupName(orderSelectInfoEntity);
			// orderSelectInfoEntity.setRefundsFlag(selectCount>0);
			AppointmentOrderSelectInfoEntity appointmentOrderSelectInfoEntity = new AppointmentOrderSelectInfoEntity();
			BeanUtils.copyProperties(orderSelectInfoEntity, appointmentOrderSelectInfoEntity);
			appointmentSelectForList.add(appointmentOrderSelectInfoEntity);

		}
		PageInfo<OrderSelectInfoEntity> pageInfo = new PageInfo<OrderSelectInfoEntity>(selectForList);
		if (order.isIspage()) {
			Map<String, Object> selectCountList = orderSelectInfoEntityMapper.selectCountAndAmountList(order);
			pageInfo.setTotal((Long) selectCountList.get("count"));
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pagetotal", pageInfo.getTotal());
		map.put("list", appointmentSelectForList);
		return map;
	}

	// 拼接小组字段
	private void getgroupName(OrderSelectInfoEntity orderSelectInfoEntity) {
		String groupNamess = orderSelectInfoEntity.getGroupNamess();
		if (!StringUtils.isEmpty(groupNamess)) {
			String workerNames = orderSelectInfoEntity.getWorkerNames();
			if (!StringUtils.isEmpty(workerNames)) {
				orderSelectInfoEntity.setWorkerNames(workerNames + "/" + groupNamess);
			} else {
				orderSelectInfoEntity.setWorkerNames(groupNamess);
			}

		}
		;

	}

	@Override
	// 查看关联订单
	public List<RelationListDto> relationList(SelectOrderVo order) {
		// OrderSelectInfoEntity selectbyOrderId =
		// orderSelectInfoEntityMapper.selectbyOrderId(order.getOrderId());
		OrderInfo selectbyOrderId = orderInfoMapper.getLastOrderInfoById(order.getOrderId());
		String superOrderId = selectbyOrderId.getSuperOrderId();
		if (StringUtils.isEmpty(superOrderId)) {
			order.setSuperOrderId(order.getOrderId());
		} else {
			order.setSuperOrderId(superOrderId);
		}
		List<OrderSelectInfoEntity> selectForList = orderSelectInfoEntityMapper.selectRelationList(order);
		List<RelationListDto> relationList = new ArrayList<RelationListDto>();
		for (OrderSelectInfoEntity orderSelectInfoEntity : selectForList) {

			RelationListDto relationListDto = new RelationListDto();
			getgroupName(orderSelectInfoEntity);
			String orderType = orderSelectInfoEntity.getOrderType();
			if (orderType.equals(OrderTypeEnum._3.getKey()) || orderType == (OrderTypeEnum._3.getKey())) {
				relationListDto.setPayStatus(PayStatusEnum._3.getKey());
			}
			BeanUtils.copyProperties(orderSelectInfoEntity, relationListDto);
			relationList.add(relationListDto);
		}
		return relationList;

	}

	// 提供查询订单列表方法
	@Override
	public List<OrderSelectInfoEntity> selectForList(String orderId) {
		SelectOrderVo order = new SelectOrderVo();
		order.setOrderId(orderId);
		return orderSelectInfoEntityMapper.selectForList(order);
	}

	// 查询订单详细
	@Override
	public OrderInfoDto selectOrderInfo(SelectOrderVo order) {
		SOrderInfoEntity selectByPrimaryKey = sOrderInfoEntityMapper.selectByPrimaryKey(order);
		// 拼接参数
		OrderInfoDto orderInfoDto = null;
		if (selectByPrimaryKey != null) {
			orderInfoDto = new OrderInfoDto();
			BeanUtils.copyProperties(selectByPrimaryKey, orderInfoDto);
			orderInfoDto.setMoneyStatus(!selectByPrimaryKey.getPayStatus().equals("1"));

		}
		Double orderAmount = 0.0;
		List<SOrderServiceInfoEntity> orderServiceInfoList = selectByPrimaryKey.getsOrderServiceInfoEntity();
		List<OrderDetailDto> orderDetailList=new ArrayList<OrderDetailDto>();
		if (orderServiceInfoList != null && orderServiceInfoList.size() > 0) {
			for (SOrderServiceInfoEntity sOrderServiceInfoEntity : orderServiceInfoList) {
				OrderServiceInfo orderServiceInfoByServiceId = orderServiceInfoMapper
						.getOrderServiceInfoByServiceId(sOrderServiceInfoEntity.getRefundServiceId());

				OrderDetailDto orderDetail = new OrderDetailDto();
				ChargeInfoDto chargeInfo = new ChargeInfoDto();
				SickRoomInfoDto sickRoomInfo = new SickRoomInfoDto();
				BeanUtils.copyProperties(sOrderServiceInfoEntity, orderDetail);
				if (selectByPrimaryKey.getOrderType().equals("3") && orderServiceInfoByServiceId != null) {
					orderDetail.setBaseBeginTime(orderServiceInfoByServiceId.getBeginTime());
					orderDetail.setBaseEndTime(orderServiceInfoByServiceId.getEndTime());
					orderDetail.setBaseDay(orderServiceInfoByServiceId.getDay());
					chargeInfo.setBaseActualTotalPrice(orderServiceInfoByServiceId.getActualTotalPrice());
					chargeInfo.setBaseDay(orderServiceInfoByServiceId.getDay());
				}else{
					chargeInfo.setBaseActualTotalPrice(sOrderServiceInfoEntity.getActualTotalPrice());
					orderDetail.setBaseDay(sOrderServiceInfoEntity.getDay());
					chargeInfo.setBaseDay(sOrderServiceInfoEntity.getDay());
				}
				BeanUtils.copyProperties(sOrderServiceInfoEntity, chargeInfo);
				// 小时单价显示成0
				// String day = chargeInfo.getDay();
				// if(!StringUtils.isEmpty(day)){
				// String[] split = day.split("\\.");
				// if(split[1].equals("0")||split[1]=="0"){
				// chargeInfo.setHourPrice(0.0);
				// }
				// }
				chargeInfo.setDiseaseGrade(sOrderServiceInfoEntity.getIllnessGrade());
				chargeInfo.setDiseaseGradeName(sOrderServiceInfoEntity.getIllnessGradeName());
				BeanUtils.copyProperties(sOrderServiceInfoEntity, sickRoomInfo);
				sickRoomInfo.setBedNumber(sOrderServiceInfoEntity.getHospitalBed());
				// BeanUtils.copyProperties(sOrderServiceInfoEntity,
				// orderDetail);
				orderDetail.setChargeInfo(chargeInfo);
				orderDetail.setSickRoomInfo(sickRoomInfo);
				orderAmount += sOrderServiceInfoEntity.getActualTotalPrice() == null ? 0
						: sOrderServiceInfoEntity.getActualTotalPrice();
				orderAmount += sOrderServiceInfoEntity.getAdditionalPrice() == null||sOrderServiceInfoEntity.getHasAdditionalPrice().equals("0") ? 0
						: sOrderServiceInfoEntity.getAdditionalPrice();
				List<SOrderServiceNurseInfoEntity> orderServiceNurseInfoList = sOrderServiceInfoEntity
						.getSOrderServiceNurseInfoEntity();
				List<WorkerDto> workerVoList = new ArrayList<WorkerDto>();
				if (orderServiceNurseInfoList != null && orderServiceNurseInfoList.size() > 0) {
					SOrderServiceNurseInfoEntity sOrderServiceNurseInfoEntity = orderServiceNurseInfoList.get(0);
					WorkerInfoDto workerInfo = new WorkerInfoDto();
					BeanUtils.copyProperties(sOrderServiceNurseInfoEntity, workerInfo);
					BeanUtils.copyProperties(sOrderServiceInfoEntity, workerInfo);
					for (SOrderServiceNurseInfoEntity sOrderServiceNurseInfoEntity2 : orderServiceNurseInfoList) {
						WorkerDto workerVo = new WorkerDto();
						BeanUtils.copyProperties(sOrderServiceNurseInfoEntity2, workerVo);
						// if(!StringUtils.isEmpty(sOrderServiceNurseInfoEntity2.getGroupId())){
						// workerVo.setWorkerId(sOrderServiceNurseInfoEntity2.getGroupId());
						// }
						if (!StringUtils.isEmpty(sOrderServiceNurseInfoEntity2.getGroupName())) {
							workerVo.setWorkerName(sOrderServiceNurseInfoEntity2.getGroupName());
						}
						//退款单时为了去原订单护工资费
						String serviceId = sOrderServiceNurseInfoEntity2.getServiceId();
						String workerId = sOrderServiceNurseInfoEntity2.getWorkerId();
						OrderServiceNurseInfo selectbaseinfobyworkerId = selectbaseinfobyworkerId(serviceId, workerId);
						if(selectByPrimaryKey.getOrderType().equals("3")&&selectbaseinfobyworkerId!=null){
							workerVo.setBaseTotalPay(selectbaseinfobyworkerId.getTotalPay());
							
						}else{
							workerVo.setBaseTotalPay(sOrderServiceNurseInfoEntity2.getTotalPay());
						}
						workerVo.setHourPay(sOrderServiceNurseInfoEntity2.getOneHourPay());
						workerVoList.add(workerVo);
					}
					workerInfo.setWorkers(workerVoList);
					orderDetail.setWorkerInfo(workerInfo);

				} else {
					WorkerInfoDto workerInfo = new WorkerInfoDto();
					workerInfo.setWorkers(workerVoList);
					orderDetail.setWorkerInfo(workerInfo);
				}

				orderDetailList.add(orderDetail);

			}
			orderInfoDto.setOrderDetail(orderDetailList);

		} else {
			// OrderDetailDto orderDetail=new OrderDetailDto();
			// orderDetail.setChargeInfo(new ChargeInfoDto());
			// orderDetail.setSickRoomInfo(new SickRoomInfoDto());
			// WorkerInfoDto workerInfo = new WorkerInfoDto();
			// List<WorkerDto> workerVoList=new ArrayList<WorkerDto>();
			// workerInfo.setWorkers(workerVoList);
			// orderDetail.setWorkerInfo(workerInfo);
			// orderDetailList.add(orderDetail);
			orderInfoDto.setOrderDetail(new ArrayList<>());
		}
		// Double actuaAmount=0.0;
		// Boolean flag=true;
		// List<OrderRefundInfo> selectRefundList =
		// iChareOrderService.selectRefundList(order.getOrderId());
		// if (selectRefundList!=null&&selectRefundList.size()>0){
		// for (int i = 0; i < selectRefundList.size(); i++)
		//
		// {
		// if(selectRefundList.get(i).getRefundDealStatus().equals(RefundDealStatus._1.getKey())||selectRefundList.get(i).getRefundDealStatus()==RefundDealStatus._1.getKey()){
		// //仅有一次同意退款生效
		// if(!flag){
		// selectRefundList.remove(i);
		// continue;
		// }
		// flag=false;
		// actuaAmount-=selectRefundList.get(i).getRefundActualAmount();
		// }
		// }
		// orderInfoDto.setRefund(selectRefundList);
		// }
		SettlementDto settlementDto = new SettlementDto();
		List<OrderChargeInfo> selectChareList = iChareOrderService.selectChareList(order.getOrderId());
		String serviceOrderTime = "";
		if (null != selectChareList && selectChareList.size() > 0) {
			OrderChargeInfo orderChargeInfo = selectChareList.get(0);
			BeanUtils.copyProperties(orderChargeInfo, settlementDto);

			String userId = orderChargeInfo.getUserId();
			if (!StringUtils.isEmpty(userId)) {
				UserAccount user = userAccountMapper.selectByPrimaryKey(Integer.parseInt(userId));
				if (null != user) {
					String userName = user.getUserRealName();
					settlementDto.setUserName(userName);
				}
			}
			
			//如果是线上支付
			
			OrderPayInfo selectPaybyorderid = selectPaybyorderid(order.getOrderId());
			settlementDto.setReqLogNo(selectPaybyorderid.getReqLogNo());
				settlementDto.setDealTime(selectPaybyorderid.getDealTime());
			settlementDto.setMidUuid(selectPaybyorderid.getMidUuid());
			OrderPayAccount selectAccountbyid = selectAccountbyid(selectPaybyorderid.getMidUuid());
			settlementDto.setMidName(selectAccountbyid.getMidName());
			serviceOrderTime = orderChargeInfo.getServiceOrderTime();
			// Double selectOrdertotalAmount =
			// selectOrdertotalAmount(orderAmount);
			// orderInfoDto.getActuaAmount()
			settlementDto.setAmount(orderAmount);

		}

		// List<SettlementDto> settlementList=new ArrayList<SettlementDto>();
		// Date time =TimeUtils.getDateByString("1900-01-01 00:00:00",
		// TimeType.yyyy_MM_dd_HH_mm_ss);
		// //退款只有在已同意才显示 并且只有一条
		// SettlementDto settlementDtoround =null;
		// if (selectChareList!=null&&selectChareList.size()>0) {
		// for (OrderChargeInfo orderChargeInfo : selectChareList) {
		// SettlementDto settlementDto = new SettlementDto();
		// BeanUtils.copyProperties(orderChargeInfo, settlementDto);
		// settlementDto.setFundType(orderChargeInfo.getTransType());
		// if(settlementDto.getFeeType().equals(FeeTypeEnum._3.getKey())){
		// if(flag){
		// continue;
		// }else{
		// if(settlementDto.getTime().getTime()>time.getTime()){
		// settlementDtoround=settlementDto;
		// time=settlementDto.getTime();
		// continue;
		// }else {
		// continue;
		// }
		//
		//
		// }
		// }
		// settlementList.add(settlementDto);
		// Double amount = settlementDto.getAmount();
		// actuaAmount+=StringUtils.isEmpty(amount)?0:amount;
		// }
		// if(settlementDtoround!=null){
		// settlementDtoround.setAmount(settlementDtoround.getAmount()==null?0.0:settlementDtoround.getAmount()*(-1));
		// settlementList.add(settlementDtoround);
		// }
		// orderInfoDto.setSettlement(selectChareList);

		// orderInfoDto.setActuaAmount(actuaAmount);
		// orderInfoDto.setOrderAmount(orderAmount);
		orderInfoDto.setServiceOrderTime(serviceOrderTime);
		orderInfoDto.setReceiptDetail(settlementDto);
		if (orderInfoDto.getOrderUpdateFlag().equals(OrderUpdateFlagEnum._0.getKey())) {
			updateOrderUpdateFlag(orderInfoDto.getOrderId());
		}
		return orderInfoDto;

	}
	//根据orderid获取对账表相关信息
		private OrderPayInfo selectPaybyorderid(String orderId){
			OrderPayInfo orderPayInfo1=new OrderPayInfo();
			orderPayInfo1.setOrderId(orderId);
			List<OrderPayInfo> select = orderPayInfoMapper.select(orderPayInfo1);
			if(null!=select&&select.size()>0){
				return select.get(0);
			}else
			return new OrderPayInfo();
		}
		//根据商户号获取商户表的信息
			private OrderPayAccount selectAccountbyid(String midUuid){
				OrderPayAccount orderPayAccount=new OrderPayAccount();
				orderPayAccount.setMidUuid(StringUtils.isEmpty(midUuid)?"":midUuid);
				orderPayAccount.setIsDel("0");
				List<OrderPayAccount> select = orderPayAccountMapper.select(orderPayAccount);
				if(null!=select&&select.size()>0){
					return select.get(0);
				}else
				return new OrderPayAccount();
			}
			//根据护工id和serviceid查看退款单信息
	private OrderServiceNurseInfo selectbaseinfobyworkerId (String serviceId,String workerId){
		OrderServiceNurseInfo orderServiceNurseInfo=new OrderServiceNurseInfo();
		orderServiceNurseInfo.setRefundServiceId(serviceId);
		orderServiceNurseInfo.setWorkerId(workerId);
		orderServiceNurseInfo.setCancel("0");
		List<OrderServiceNurseInfo> select = orderServiceNurseInfoMapper.select(orderServiceNurseInfo);
		if(null!=select&&select.size()>0){
			return select.get(0);
		}else{
			return new OrderServiceNurseInfo();
		}
		}
	// 更改订单已读状态
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	private void updateOrderUpdateFlag(String orderid) {
		orderInfoMapper.updateOrderUpdateFlag(OrderUpdateFlagEnum._2.getKey(), orderid);
	}

	// 查询未读订单数量
	@Override
	public int selectUnreadOrder(String hospitalId) {
		return orderInfoMapper.selectUnreadOrder(hospitalId);
	}

	@Override
	// 查询订单总价格
	public Double selectOrdertotalAmount(String orderid) {
		OrderSelectInfoEntity selectbyOrderId = orderSelectInfoEntityMapper.selectbyOrderId(orderid);
		if (null == selectbyOrderId) {
			return null;
		}
		return selectbyOrderId.getTotalAmount();
	}

	// 更改订单付款状态为已付款
	@Override
	public void updateOrderInfoStatus(String id, PayStatusEnum payStatusEnum) {
		if (null == id) {
			throw new RuntimeException("异常信息: id不能为空");
		}
		Boolean flag = orderInfoMapper.updatePayStatusById(payStatusEnum.getKey(), Integer.valueOf(id));
		if (!flag) {
			throw new RuntimeException("异常信息: 更改付款状态失败");
		}

	}

	@Override
	public List<OrderSelectInfoEntity> appSelectOrderList(SelectOrderVo order, UserPatient user) {
		if (null == order) {
			order = new SelectOrderVo();
			order.setPage("1");
			order.setPageSize("10");
		}
		order.setLoginPhone(user.getPhone());
		// order.setLoginPhone("13317171717");
		PageHelper.startPage(Integer.valueOf(order.getPage()), Integer.valueOf(order.getPageSize()));
		List<OrderSelectInfoEntity> selectForList = orderSelectInfoEntityMapper.selectForList(order);
		for (OrderSelectInfoEntity orderSelectInfoEntity : selectForList) {
			String orderId = orderSelectInfoEntity.getOrderId();
			Double alreadyAmount = orderChargeInfoMapper.AlreadyAmount(orderId);
			orderSelectInfoEntity.setTotalAmount(alreadyAmount);
		}
		return selectForList;
	}

	@Override
	public AppSelectOrderInfoDto appSelectOrderInfo(SelectOrderVo order) {
		// SOrderInfoEntity selectByPrimaryKey =
		// sOrderInfoEntityMapper.selectByPrimaryKey(order);
		// if(selectByPrimaryKey==null){
		// return null;
		// }
		// AppSelectOrderInfoDto appSelectOrderInfoDto=new
		// AppSelectOrderInfoDto();
		// BeanUtils.copyProperties(selectByPrimaryKey,appSelectOrderInfoDto);
		// String returnhospitalName = selectByPrimaryKey.getHospitalName();
		// List<SOrderServiceInfoEntity> orderServiceInfoList =
		// selectByPrimaryKey.getsOrderServiceInfoEntity();
		// Double sumday=0.0;
		// Double sumhour=0.0;
		// //排序
		// if(orderServiceInfoList!=null&&orderServiceInfoList.size()>0){
		// Collections.sort(orderServiceInfoList,new
		// Comparator<SOrderServiceInfoEntity>(){
		// @Override
		// public int compare(SOrderServiceInfoEntity arg0,
		// SOrderServiceInfoEntity arg1) {
		// return arg0.getBeginTime().compareTo(arg1.getBeginTime());
		// }
		// });
		// SOrderServiceInfoEntity lastOrderServiceInfo =
		// orderServiceInfoList.get(orderServiceInfoList.size()-1);
		// //取最后一条的服务信息的护工信息
		// if(null!=lastOrderServiceInfo.getSOrderServiceNurseInfoEntity()&&lastOrderServiceInfo.getSOrderServiceNurseInfoEntity().size()>0){
		// appSelectOrderInfoDto.setServiceType(lastOrderServiceInfo.getSOrderServiceNurseInfoEntity().get(0).getServiceType());
		// returnhospitalName+=" "+lastOrderServiceInfo.getDepartmentName()+" ";
		// returnhospitalName+=lastOrderServiceInfo.getBuildingNumberName()+" ";
		// returnhospitalName+=lastOrderServiceInfo.getFloorName();
		// }else{
		// appSelectOrderInfoDto.setServiceType(null);
		// };
		//// appSelectOrderInfoDto.setServiceBeginTime(lastOrderServiceInfo.getBeginTime());
		//// appSelectOrderInfoDto.setServiceEndTime(lastOrderServiceInfo.getEndTime());
		// List<AppWorkInfoDto> appWorkInfoList=new ArrayList<AppWorkInfoDto>();
		//
		// //双层循环取护工信息
		// for (SOrderServiceInfoEntity orderServiceInfo : orderServiceInfoList)
		// {
		// String dayAndHour = orderServiceInfo.getDay();
		// if(dayAndHour!=null&&!"".equals(dayAndHour)){
		// String[] split = dayAndHour.split("\\.");
		//
		// String dayStr = split[0];
		// sumday+=Integer.valueOf(dayStr);
		// if(split.length>1){
		// String houtStr = split[1];
		// sumhour+=Integer.valueOf(houtStr);
		// }
		// }
		// List<SOrderServiceNurseInfoEntity> sOrderServiceNurseInfoList=
		// orderServiceInfo.getSOrderServiceNurseInfoEntity();
		// if(sOrderServiceNurseInfoList!=null&&sOrderServiceNurseInfoList.size()>0){
		// for (SOrderServiceNurseInfoEntity sOrderServiceNurseInfo :
		// sOrderServiceNurseInfoList) {
		// AppWorkInfoDto appWorkInfo = new AppWorkInfoDto();
		//
		// appWorkInfo.setWorkerId(sOrderServiceNurseInfo.getWorkerId());
		// appWorkInfo.setWorkerName(sOrderServiceNurseInfo.getWorkerName());
		// appWorkInfo.setBeginTime(orderServiceInfo.getBeginTime());
		// appWorkInfo.setEndTime(orderServiceInfo.getEndTime());
		// appWorkInfo.setServiceType(sOrderServiceNurseInfo.getServiceType());
		// Date nowDate = new Date();
		// //如果现在时间小于开始服务时间 则为带服务状态
		// if(nowDate.getTime()<orderServiceInfo.getBeginTime().getTime()){
		// appWorkInfo.setStatusName(ServiceStatusEnum._1.getVal());
		// }else if(nowDate.getTime()>orderServiceInfo.getEndTime().getTime()){
		// appWorkInfo.setStatusName(ServiceStatusEnum._3.getVal());
		// }else{
		// appWorkInfo.setStatusName(ServiceStatusEnum._2.getVal());
		// }
		// appWorkInfo.setAvatarPhotoUrl(sOrderServiceNurseInfo.getAvatarPhotoUrl());
		// appWorkInfo.setServiceYears(sOrderServiceNurseInfo.getServiceYears());
		// appWorkInfoList.add(appWorkInfo);
		// }
		// }
		// }
		// appSelectOrderInfoDto.setWorkers(appWorkInfoList);
		// int hourtoday=(int) (sumhour/24);
		// sumday=sumday+hourtoday;
		// sumhour=sumhour-(hourtoday*24);
		// int isumday=(int)(sumday*1);
		// int isumhour=(int)(sumhour*1);
		// appSelectOrderInfoDto.setDay(isumday+"."+isumhour);
		// }else{
		// List<AppWorkInfoDto> appWorkInfoDto=new ArrayList<AppWorkInfoDto>();
		// //初始化天数
		// appSelectOrderInfoDto.setDay("0.0");
		//
		// appSelectOrderInfoDto.setWorkers(appWorkInfoDto);
		// }
		// //已经交的钱
		// Double alreadyAmount =
		// orderChargeInfoMapper.AlreadyAmount(order.getOrderId() );
		// //订单的总价格
		// Double selectOrdertotalAmount =
		// selectOrdertotalAmount(order.getOrderId());
		// Double
		// actualDayPrice=(selectOrdertotalAmount==null?0:selectOrdertotalAmount)/(sumday+(sumhour/24));
		// appSelectOrderInfoDto.setActualTotalPrice(alreadyAmount==null?0:alreadyAmount);
		// appSelectOrderInfoDto.setActualDayPrice(actualDayPrice==null?0:actualDayPrice);
		// List<OrderRefundInfo> selectRefundFinishList =
		// iChareOrderService.selectRefundFinishList(order.getOrderId());
		// if(selectRefundFinishList!=null&&selectRefundFinishList.size()>0){
		// appSelectOrderInfoDto.setHaveRefund(true);
		// appSelectOrderInfoDto.setRefundAmount(selectRefundFinishList.get(0).getRefundAmount());
		// appSelectOrderInfoDto.setRefundActualAmount(selectRefundFinishList.get(0).getRefundActualAmount());
		// }else{
		// appSelectOrderInfoDto.setHaveRefund(false);
		// appSelectOrderInfoDto.setRefundAmount(0.0);
		// appSelectOrderInfoDto.setRefundActualAmount(0.0);
		// }
		// appSelectOrderInfoDto.setHospitalName(returnhospitalName);
		return null;
	}

	public static void main(String[] args) {
		// String url="";
		// String uid="";
		// String sendPost="";
		// boolean b = (url.contains("wz")
		// &&!Contence.isTrue_wz)||(url.contains("cz")
		// &&!Contence.isTrue_cz)||(url.contains("xw") &&!Contence.isTrue_xw )||
		// url.contains("xwCreditQuery");
		// if(b) {
		// System.out.println(url+"?"+"user_ids="+uid+"&baffle=true");
		// sendPost = eu.sendGet(url, "user_ids="+uid+"&baffle=true");
		// }else {
		// System.out.println(url+"?"+"user_ids="+uid);
		// sendPost = eu.sendGet(url, "user_ids="+uid);
		// }
		Double maxValue = Double.MAX_VALUE;
		String valueOf = String.valueOf(maxValue);
		// Long l=Long.valueOf(valueOf);
		System.out.println(valueOf);
	}

	// 查询待收款订单列表
	@Override
	public Map<String, Object> selectReceivableList(ToChargeVo toChargeVo) {
		toChargeVo.setPayStatus(PayStatusEnum._1.getKey());
		String[] orderStatuss = { OrderStatusEnum._2.getKey(), OrderStatusEnum._3.getKey(),
				OrderStatusEnum._5.getKey() };
		toChargeVo.setOrderStatuss(orderStatuss);
		String sort = toChargeVo.getSort() == null ? "" : toChargeVo.getSort();
		if (sort.contains("remainingTime")) {
			sort = sort.replaceAll("remainingTime", "diff_date");
		}
		if (sort.contains("createTime")) {
			sort = sort.replaceAll("createTime", "create_time");
		} else {
			sort = "create_time  desc";
		}
		toChargeVo.setSort(sort);
		Integer page = Integer.valueOf(StringUtils.isEmpty(toChargeVo.getPage()) ? "1" : toChargeVo.getPage());
		Integer pageSize = Integer
				.valueOf(StringUtils.isEmpty(toChargeVo.getPageSize()) ? "65536" : toChargeVo.getPageSize());
		PageHelper.startPage(page, pageSize, false);
		List<OrderSelectInfoEntity> selectForList = orderSelectInfoEntityMapper.selectForReceivable(toChargeVo);
		PageInfo<OrderSelectInfoEntity> pageInfo = new PageInfo<OrderSelectInfoEntity>(selectForList);
		List<OrderSelectInfoEntity> list = pageInfo.getList();
		List<OrderSelectInfoReceivableEntity> receivablelist = new ArrayList<OrderSelectInfoReceivableEntity>();
		for (int i = 0; i < list.size(); i++) {
			OrderSelectInfoEntity orderSelectInfoEntity = list.get(i);
			getgroupName(orderSelectInfoEntity);
			OrderSelectInfoReceivableEntity orderSelectInfoReceivableEntity = new OrderSelectInfoReceivableEntity();
			BeanUtils.copyProperties(orderSelectInfoEntity, orderSelectInfoReceivableEntity);
			String orderId = orderSelectInfoEntity.getOrderId();
			OrderInfo orderInfo = new OrderInfo();
			orderInfo.setDeflag("0");
			orderInfo.setRefundOrderId(orderId);
			// int selectCount = orderInfoMapper.selectCount(orderInfo);
			// orderSelectInfoReceivableEntity.setRefundsFlag(selectCount>0);
			receivablelist.add(orderSelectInfoReceivableEntity);
		}
		long total = orderSelectInfoEntityMapper.selectCountForReceivable(toChargeVo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", receivablelist);
		map.put("total", total);
		return map;
	}

	// 查询待收款订单列表
	public PageInfo<OrderSelectInfoEntity> selectReceivableListExcel(ToChargeVo toChargeVo) {
		toChargeVo.setPayStatus(PayStatusEnum._1.getKey());
		PageHelper.startPage(Integer.valueOf(toChargeVo.getPage()), Integer.valueOf(toChargeVo.getPageSize()));
		List<OrderSelectInfoEntity> selectForList = orderSelectInfoEntityMapper.selectForReceivable(toChargeVo);

		PageInfo<OrderSelectInfoEntity> pageInfo = new PageInfo<OrderSelectInfoEntity>(selectForList);
		// List<OrderSelectInfoEntity> list = pageInfo.getList();
		// for (int i=0;i<list.size();i++) {
		// OrderSelectInfoEntity orderSelectInfoEntity = list.get(i);
		// String orderId = orderSelectInfoEntity.getOrderId();
		// Double receivableAmount =
		// iChareOrderService.selectReceivableAmount(orderId);
		// orderSelectInfoEntity.setReceivableAmount(String.valueOf(receivableAmount));
		// String minReceivableAmount = toChargeVo.getMinReceivableAmount();
		// String maxReceivableAmount = toChargeVo.getMaxReceivableAmount();
		// if(!StringUtils.isEmpty(minReceivableAmount)&&receivableAmount<Double.valueOf(minReceivableAmount)){
		// list.remove(orderSelectInfoEntity);
		// i--;
		// }
		// if(!StringUtils.isEmpty(maxReceivableAmount)&&receivableAmount>Double.valueOf(maxReceivableAmount)){
		// list.remove(orderSelectInfoEntity);
		// i--;
		// }
		// }
		return pageInfo;
	}

	// 查询待续费订单列表
	@Override
	public Map<String, Object> toChargeList(ToChargeVo toChargeVo) {
		// toChargeVo.setPayStatus(PayStatusEnum._2.getKey());
		String[] paystatuss = { PayStatusEnum._1.getKey(), PayStatusEnum._2.getKey() };
		String[] orderStatuss = { OrderStatusEnum._2.getKey(), OrderStatusEnum._3.getKey(),
				OrderStatusEnum._5.getKey() };
		toChargeVo.setOrderStatuss(orderStatuss);
		toChargeVo.setPayStatuss(paystatuss);
		// 查询未被续费的订单
		toChargeVo.setRenewFlag("0");
		// String strHour = toChargeVo.getRemainingTimeHour();
		String strDay = toChargeVo.getRemainingTimeDay();
		String beginstrDay = toChargeVo.getBeginRemainingTimeDay();
		String endstrDay = toChargeVo.getEndRemainingTimeDay();
		// 如果等于空查询全量的数据

		if (StringUtils.isEmpty(beginstrDay)) {
			beginstrDay = String.valueOf(Integer.MIN_VALUE / 24000 / 25);
		}
		if (StringUtils.isEmpty(endstrDay)) {
			endstrDay = String.valueOf(Integer.MAX_VALUE / 24000 / 25);
		}
		Pattern pattern = Pattern.compile("^(\\-?)\\d+$");
		boolean flag = pattern.matcher(beginstrDay).matches();
		boolean endflag = pattern.matcher(endstrDay).matches();
		if (!flag || !endflag) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("total", 0L);
			map.put("list", null);
			return map;
		}

		// int
		// second=(Integer.parseInt(StringUtils.isEmpty(strDay)?"0":strDay)*3600*24)+(Integer.parseInt(StringUtils.isEmpty(strHour)?"0":strHour)*3600);
		// int
		// startsecond=((Integer.parseInt(StringUtils.isEmpty(beginstrDay)?"0":beginstrDay))*3600*24);
		// toChargeVo.setStartdiffDate(startsecond);
		// int
		// endsecond=((Integer.parseInt(StringUtils.isEmpty(endstrDay)?"0":endstrDay))*3600*24);
		// toChargeVo.setEnddiffDate(endsecond);
		int startseconds = Integer.parseInt(StringUtils.isEmpty(beginstrDay) ? "0" : beginstrDay);
		int startsecond = (startseconds * 3600 * 24);
		int endseconds = Integer.parseInt(StringUtils.isEmpty(endstrDay) ? "0" : endstrDay);
		int endsecond = (endseconds * 3600 * 24);
		toChargeVo.setStartdiffDate(startsecond);
		toChargeVo.setEnddiffDate(endsecond);
		// String isCreateTimeAsc = toChargeVo.getIsCreateTimeAsc();
		// String isRemainingTimeAsc = toChargeVo.getIsRemainingTimeAsc();
		// if(SortEnum._1.getKey().equals(isCreateTimeAsc)){
		// toChargeVo.setSort("create_time "+SortEnum._1.getVal());
		// }
		// if(SortEnum._2.getKey().equals(isCreateTimeAsc)){
		// toChargeVo.setSort("create_time "+SortEnum._2.getVal());
		// }
		// if(SortEnum._1.getKey().equals(isRemainingTimeAsc)){
		// toChargeVo.setSort("diff_date "+SortEnum._1.getVal());
		// }
		// if(SortEnum._2.getKey().equals(isRemainingTimeAsc)){
		// toChargeVo.setSort("diff_date "+SortEnum._2.getVal());
		// }
		String sort = toChargeVo.getSort() == null ? "" : toChargeVo.getSort();
		if (sort.contains("remainingTime")) {
			sort = sort.replaceAll("remainingTime", "diff_date");
		} else if (sort.contains("createTime")) {
			sort = sort.replaceAll("createTime", "create_time");
		} else {
			sort = "diff_date  desc";
		}

		toChargeVo.setSort(sort);
		PageHelper.startPage(Integer.valueOf(StringUtils.isEmpty(toChargeVo.getPage()) ? "1" : toChargeVo.getPage()),
				Integer.valueOf(StringUtils.isEmpty(toChargeVo.getPageSize()) ? "65536"
						: toChargeVo.getPageSize()));
		List<OrderSelectInfoEntity> selectForList = orderSelectInfoEntityMapper.selectForReceivable(toChargeVo);

		PageInfo<OrderSelectInfoEntity> pageInfo = new PageInfo<OrderSelectInfoEntity>(selectForList);
		List<OrderSelectInfoEntity> list = pageInfo.getList();
		List<OrderSelectInfoToChargeEntity> toChargeList = new ArrayList<OrderSelectInfoToChargeEntity>();
		for (OrderSelectInfoEntity orderSelectInfoEntity : list) {
			getgroupName(orderSelectInfoEntity);
			int secondre = Integer.parseInt(StringUtils.isEmpty(orderSelectInfoEntity.getDiffDate()) ? "0"
					: orderSelectInfoEntity.getDiffDate());
			if (StringUtils.isEmpty(secondre)) {
				orderSelectInfoEntity.setRemainingTime("0.0");
			} else {
				int d = 0;
				int h = 0;
				int temp = secondre % (3600 * 24);
				if (secondre > (3600 * 24) || secondre < -(3600 * 24)) {
					d = secondre / (3600 * 24);
				}
				h = temp / 3600;
				String isPlusMinus = "";
				if (d < 0 || h < 0) {
					isPlusMinus = "-";
				}
				orderSelectInfoEntity.setRemainingTime(
						isPlusMinus + (Math.abs(d) == 0 ? "" : Math.abs(d) + "天") + Math.abs(h) + "小时");
			}
			OrderSelectInfoToChargeEntity orderSelectInfoToChargeEntity = new OrderSelectInfoToChargeEntity();
			BeanUtils.copyProperties(orderSelectInfoEntity, orderSelectInfoToChargeEntity);
			String orderId = orderSelectInfoEntity.getOrderId();
			OrderInfo orderInfo = new OrderInfo();
			orderInfo.setDeflag("0");
			orderInfo.setRefundOrderId(orderId);
			// int selectCount = orderInfoMapper.selectCount(orderInfo);
			// orderSelectInfoToChargeEntity.setRefundsFlag(selectCount>0);
			toChargeList.add(orderSelectInfoToChargeEntity);
		}
		// long total = pageInfo.getTotal();
		long total = orderSelectInfoEntityMapper.selectCountForReceivable(toChargeVo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", toChargeList);
		map.put("total", total);
		return map;
	}

	// 根据订单号获取订单基础表信息
	@Override
	public OrderInfo selectOrderByorderid(String orderid) {
		OrderInfo orderInfo = new OrderInfo();
		orderInfo.setOrderId(orderid);
		orderInfo.setDeflag("0");
		List<OrderInfo> select = orderInfoMapper.select(orderInfo);
		if (null != select && select.size() > 0)
			return select.get(0);
		else
			return null;
	}

	// 取消续费
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public Boolean cancelrenewal(String orderid) {

		return orderInfoMapper.cancelrenewal(orderid);
	}

	// 修改线上支付 订单状态
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public Boolean changeOnlineOrderStatusStatus(String orderid, OrderStatusEnum orderStatus,
			AccountFlagEnum accountFlag,PayStatusEnum payStatus) {

		return orderInfoMapper.changeOnlineOrderStatusStatus(orderid, orderStatus.getKey(), accountFlag.getKey(),payStatus.getKey());
	}

	// 修改收据表退款状态为已退款
	@Override
	public void updateRefundStatus(String orderId,String status) {
		orderChargeInfoMapper.updateRefundStatus(orderId,status);

	}
}
